/*
 * @Author: your name
 * @Date: 2021-06-11 11:05:46
 * @LastEditTime: 2021-06-16 17:31:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bazai_ebook\src\store\modules\store.js
 */
import {
  SET_HOT_SEARCH_OFFSETY,
  SET_FLAP_CARD_VISIBLE,
  SET_IS_EDIT_MODE,
  SET_SHELF_LIST,
  SET_SHELF_SELECTED,
  SET_SHELF_TITLE_VISIBLE,
  SET_SHELF_CATEGORY,
  SET_CURRENT_TYPE
} from '@/store/mutations-type'

const store = {
  namespaced: true,
  state: () => ({
    hotSearchOffsetY: 0,
    flapCardVisible: false,
    isEditMode: false, // 是否进入编辑模式
    shelfList: [], // 书架图书列表
    shelfSelected: [], // 书架图书选中的列表
    shelfTitleVisible: true,
    shelfCategory: [], // 书架分类列表数据
    currentType: 1 // 书架列表为1，书架分类列表为2
  }),
  mutations: {
    [SET_HOT_SEARCH_OFFSETY]: (state, offsetY) => {
      state.hotSearchOffsetY = offsetY
    },
    [SET_FLAP_CARD_VISIBLE]: (state, visible) => {
      state.flapCardVisible = visible
    },
    [SET_IS_EDIT_MODE]: (state, isEditMode) => {
      state.isEditMode = isEditMode
    },
    [SET_SHELF_LIST]: (state, list) => {
      state.shelfList = list
    },
    [SET_SHELF_SELECTED]: (state, selected) => {
      state.shelfSelected = selected
    },
    [SET_SHELF_TITLE_VISIBLE]: (state, visible) => {
      state.shelfTitleVisible = visible
    },
    [SET_SHELF_CATEGORY]: (state, category) => {
      state.shelfCategory = category
    },
    [SET_CURRENT_TYPE]: (state, type) => {
      state.currentType = type
    }
  },
  actions: {
    setHotSearchOffsetY: ({ commit }, offsetY) => {
      return commit('SET_HOT_SEARCH_OFFSETY', offsetY)
    },
    setFlapCardVisible: ({ commit }, flapCardVisible) => {
      return commit('SET_FLAP_CARD_VISIBLE', flapCardVisible)
    },
    setIsEditMode ({ commit }, isEditMode) {
      return commit('SET_IS_EDIT_MODE', isEditMode)
    },
    setShelfList ({ commit }, list) {
      return commit('SET_SHELF_LIST', list)
    },
    setShelfSelected ({ commit }, selected) {
      return commit('SET_SHELF_SELECTED', selected)
    },
    setShelfTitleVisible ({ commit }, visible) {
      return commit('SET_SHELF_TITLE_VISIBLE', visible)
    },
    setShelfCategory ({ commit }, category) {
      return commit('SET_SHELF_CATEGORY', category)
    },
    setCurrentType ({ commit }, type) {
      return commit('SET_CURRENT_TYPE', type)
    }
  },
  getters: {
    hotSearchOffsetY: state => state.hotSearchOffsetY,
    flapCardVisible: state => state.flapCardVisible,
    isEditMode: state => state.isEditMode,
    shelfList: state => state.shelfList,
    shelfSelected: state => state.shelfSelected,
    shelfTitleVisible: state => state.shelfTitleVisible,
    shelfCategory: state => state.shelfCategory,
    currentType: state => state.currentType
  }
}

export default store
